package com.baozhun.mall.common.adapter

import com.baozhun.mall.common.BR
import com.baozhun.mall.common.R
import com.baozhun.mall.common.base.BaseListAdapter
import com.baozhun.mall.common.databinding.ItemCommonChooseBinding
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder

/**
 * @Title：功能图片适配器
 * @Description：
 * @Author：xuefeng.zhu
 * @Since：2022/11/10
 * @Version：1.0.0
 */
class CommonChooseAdapter(data: MutableList<String>?) :
    BaseListAdapter<String, ItemCommonChooseBinding>(R.layout.item_common_choose, data) {
    var mChoosePosition: Int = -1

    override fun convert(holder: BaseDataBindingHolder<ItemCommonChooseBinding>, item: String) {
        holder.dataBinding?.setVariable(BR.content, item)
        holder.dataBinding?.setVariable(BR.isSelect, holder.adapterPosition == mChoosePosition)
        holder.dataBinding?.executePendingBindings()
    }

    /**
     * 更新选中状态
     */
    fun updateChooseStatus(position: Int) {
        mChoosePosition = position
        notifyDataSetChanged()
    }
}


